import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueSetupExtend from 'vite-plugin-vue-setup-extend'
import { viteMockServe } from 'vite-plugin-mock'
// https://vitejs.dev/config/
export default defineConfig({
  base:'linter',
  plugins: [
    vue(),
    vueSetupExtend(),
    // mock服务
    viteMockServe({
      supportTs: false,
      logger: false,
      mockPath: "./src/mock/",
    }),
  ],
  define:{
    'process.env': {}
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
      '@config': fileURLToPath(new URL('./src/config', import.meta.url)),
      '@api': fileURLToPath(new URL('./src/apis', import.meta.url))
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        javascriptEnabled: true,
        additionalData: '@use "./src/assets/sass/variable.scss" as *;'
      }
    }
  },
  server: {
    open: true,
    proxy: {
      '/spring': {
        target: 'http://127.0.0.1:8080',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/spring/, '')
      },
      '/flask': {
        target: 'http://127.0.0.1:5000',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/flask/,''),
        ws: true
      },
      '/api': {
        target: 'http://127.0.0.1:8088',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/api/,''),
        ws: true
      },
    }
  }
})
